/*
 * @lc app=leetcode.cn id=88 lang=javascript
 *
 * [88] 合并两个有序数组
 */

// @lc code=start
/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */
var merge = function (nums1, m, nums2, n) {
  let temp = [];
  let point1 = 0;
  let point2 = 0;
  while (point1 < m || point2 < n) {
    const val1 = nums1[point1];
    const val2 = nums2[point2];
    if (point1 === m || val1 > val2) {
      temp.push(val2);
      point2++;
    } else if (point2 === n || val1 <= val2) {
      temp.push(val1);
      point1++;
    }
  }

  for(let i = 0; i < temp.length; i++) {
    nums1[i] = temp[i];
  }
};
// @lc code=end
